home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_04 / allison / declare.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  605 b   |  33 lines

  1. LISTING 13 - Shows that declarations are statements
  2.  
  3. // declare.cpp
  4. #include <iostream.h>
  5.  
  6. main()
  7. {
  8.     int a[] = {0,1,2,3,4};
  9.  
  10.     // Print address and size
  11.     cout << "a == " << (void *) a << endl;
  12.     cout << "sizeof(a) == " << sizeof(a) << endl;
  13.  
  14.     // Print forwards
  15.     size_t n = sizeof a / sizeof a[0];
  16.     for (int i = 0; i < n; ++i)
  17.         cout << a[i] << ' ';
  18.     cout << endl;
  19.  
  20.     // Then backwards
  21.     for (i = n-1; i >= 0; --i)
  22.         cout << a[i] << ' ';
  23.     cout << endl;
  24.     return 0;
  25. }
  26.  
  27. // Output:
  28. a == 0xffec
  29. sizeof(a) == 10
  30. 0 1 2 3 4 
  31. 4 3 2 1 0 
  32.  
  33.